﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Web.Configuration;

namespace StsServices
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、svc 和配置文件中的类名“Service1”。
    // 注意: 为了启动 WCF 测试客户端以测试此服务，请在解决方案资源管理器中选择 Service1.svc 或 Service1.svc.cs，然后开始调试。
    public class StsService : IStsService
    {
        private const char NEW_PROP = ',';
        private const char NEW_LINE = ';';
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite == null)
            {
                throw new ArgumentNullException("composite");
            }
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }
        public string GetTestPapers(int id, string code, string tn, string tc)
        {
            StringBuilder sb = new StringBuilder("");

            string sql = "select * from t_testpaper";

            string connString =  WebConfigurationManager.ConnectionStrings["Theme"].ConnectionString;
            SqlConnection conn = new SqlConnection(connString);

            SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, conn);
            DataSet ds = new DataSet();
            dataAdapter.Fill(ds);

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                sb.Append(dr[1].ToString().Trim());
                for (int index = 2; index < 4; index++)
                {
                    sb.Append(NEW_PROP);
                    sb.Append(dr[index].ToString().Trim());    
                } 
                sb.Append(NEW_LINE);
            }


            return sb.ToString();
        }

    }
}
